#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

#export QT_SELECT=qt5

ifdef INSTALL_DIR
    LIB_PARAS += ${INSTALL_DIR}/lib
endif

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
BUILD_DIR = "build_$(DEB_HOST_MULTIARCH)"
PACKAGE_DIR = "debian/rabbitremotecontrol"

%:
	dh $@

# Debian 维护者指南: https://www.debian.org/doc/manuals/debmake-doc/index.zh-cn.html
# Debian 新维护者手册: https://www.debian.org/doc/manuals/maint-guide/dreq.zh-cn.html#rules
# See: man debhelper
# This is example for Cmake (See https://bugs.debian.org/641051 )
override_dh_auto_configure:
	dh_auto_configure -B$(BUILD_DIR) -- -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
            -DBUILD_FREERDP=ON \
            -DCMAKE_INSTALL_PREFIX=/opt/RabbitRemoteControl \
            -DRabbitCommon_ROOT=${RabbitCommon_ROOT} \
            -DCMARK_SHARED=OFF \
            -DCMARK_TESTS=OFF \
            -DCMARK_STATIC=ON \
            ${PARAS}

override_dh_auto_build:
#	dh_auto_build --parallel $(nproc) -B$(BUILD_DIR)
	cmake --build $(BUILD_DIR) --config Release --parallel $(nproc)

override_dh_auto_install:
	cmake --install $(BUILD_DIR) --config Release \
		--component DependLibraries --strip \
		--prefix $(PACKAGE_DIR)/opt/RabbitRemoteControl
	cmake --install $(BUILD_DIR) --config Release \
		--component Runtime --strip \
		--prefix $(PACKAGE_DIR)/opt/RabbitRemoteControl
	cmake --install $(BUILD_DIR) --config Release \
		--component Application --strip \
		--prefix $(PACKAGE_DIR)/opt/RabbitRemoteControl	
	cmake --install $(BUILD_DIR) --config Release \
		--component Plugin --strip \
		--prefix $(PACKAGE_DIR)/opt/RabbitRemoteControl

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info -l`pwd`/$(PACKAGE_DIR)/opt/RabbitRemoteControl/lib:`pwd`/$(PACKAGE_DIR)/opt/RabbitRemoteControl/lib/`uname -m`-linux-gnu:$(LIB_PARAS)

override_dh_builddeb:
	dh_builddeb --package=rabbitremotecontrol -P$(PACKAGE_DIR)
